package tjs.study.mini.spingmvcmini.config.servlet;

import tjs.study.mini.spingmvcmini.config.annotion.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import java.util.Objects;

/**
 * @author nicky
 * @date 2021/9/7 下午3:24
 */
public class RequestMappingInfo {
    private String path;
    private String method;

    public RequestMappingInfo(String path, RequestMethod method) {
        this.path = path;
        this.method = method.toString();
    }

    public RequestMappingInfo(HttpServletRequest request) {
        this.path = request.getRequestURI();
        this.method = request.getMethod();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        RequestMappingInfo that = (RequestMappingInfo) o;
        return Objects.equals(path, that.path) &&
                Objects.equals(method, that.method);
    }

    @Override
    public int hashCode() {
        // 重写hashCode
        return this.path.hashCode() * 31 + this.method.hashCode() * 31;
    }


}
